//https://www.bilibili.com/video/BV1d54y1f7B3/?spm_id_from=333.337.search-card.all.click&vd_source=d6fe65f095f01f05591e89d810720ccc
// 2024-10-19

public class P017_排列硬币_牛顿迭代 {

    public static void main(String[] args) {
        System.out.println(fun(10));
    }


    // x*x + x = 2n,x=根号(2n-x)
    private static int fun(int n) {
        if (n == 0 || n == 1) return n;
        return (int) fun(n,n);
    }

    private static double fun(double x,int n) {
        double res = ((2*n - x)/x + x) / 2;
        if (res == x) return x;
        else return fun(res,n);
    }
}
